<template>
    <div class="courses-nav jx-content">
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="题目类型 :">
                <el-select v-model="questionTypeMessage" placeholder="请选择" @change="getTopicModel">
                    <el-option v-for="(item,index) in questionTypeList" :key="index" :label="item.message" :value="item.type"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="试题章节 :">
                <el-select :clearable="true" v-model="chapterMessage" placeholder="请选择" @change="getchapterModel">
                    <el-option v-for="(item,index) in chapterList" :key="index" :label="item.chapterName" :value="item.chapterId"></el-option>
                </el-option>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import axios from "axios";
import $ from "jquery";
export default {
    data() {
        return {
            searchForm: {
                //当前页
                pageNum: 1,
                //每页显示条数
                //pageSize:10,
                //关键词
                keyWord: "",
                //章节id
                chapterId: 0,
                //题型序号
                questionType: 0
            },
            //题目类型名称
            questionTypeMessage: '选择题',
            //题目类型数组
            questionTypeList: [],
            //章节名称
            chapterMessage: "",
            //章节数组
            chapterList: [],
            options: [
                {
                type: "1",
                message: "选择题"
                },
                {
                type: "2",
                message: "判断题"
                },
                {
                type: "3",
                message: "填空题"
                },
                {
                type: "4",
                message: "简答题"
                },
                {
                type: "5",
                message: "编程题"
                },
                {
                type: "6",
                message: "实验题"
                }
            ]
        };
    },
    watch: {
        questionTypeMessage(val) {
            //1选择 addChoiceQuestion
            //2判断 addJudge
            //3填空 addFillInTheBlanks
            //4简答 AddShortAnswerQuestions
            //5编程 addChoiceQuestion
            //6实验 AddExperimental
            val = Number(val);
            //console.log(val);
            switch (val) {
                case 1:
                this.$router.push({ path: "/addChoiceQuestion" });
                break;
                case 2:
                this.$router.push(
                    { path: "/addJudge" });
                break;
                case 3:
                this.$router.push({ path: "/addFillInTheBlanks" });
                break;
                case 4:
                this.$router.push({ path: "/AddShortAnswerQuestions" });
                break;
                case 5:
                this.$router.push({ path: "/addJudge" });
                break;
                case 6:
                this.$router.push({ path: "/addExperimental" });
                break;
                default:
                console.log(1234);
            }
        }
    },
    mounted() {
        this.init();
    },
    methods: {
        init() {
            this.getTopicSelected();
        },
        //获取题目类型和章节下拉
        getTopicSelected() {
            var that = this;
            axios
            .get("/tes/course/"+this.$localstorage.getLocalStorage('setCourseId')+"/businessType/1/question-repository/dropdown-list")
            .then(function(res) {
                console.log("成功");
                console.log(res);
                if (res.status === 200) {
                    if (res.data.code === 200) {
                        console.log(res.message);
                        //赋值题目类型
                        let questionTypeList = res.data.data.questionTypeList;
                        that.questionTypeList = questionTypeList;
                        //赋值章节列表
                        let chapterList = res.data.data.chapterList;
                        that.chapterList = chapterList;
                    }
                }
            })
            .catch(function(err) {
                if (err.response) {
                    console.log(err.response);
                }
            });
        },
        //获取题目类型
        getTopicModel(val) {
            this.searchForm.questionType = val;
        },
        //获取章节
        getchapterModel(val) {
            this.searchForm.chapterId = val;
        }
    }
};
</script>
